<?php
  class HqBaseController extends Controller{
  	  public $layout='/layouts/column2';

  	  /**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			'postOnly + delete', // we only allow deletion via POST request
		);
	}
	public function isAdmin(CWebUser $user, CAccessRule $rule){
    	$user = Yii::app()->user;
        if ($user->isGuest){
			$this->redirect($this->createUrl('/user/login/index'));
			return true;
        }
        else{
        	$x = User::model()->findByAttributes(array('user_name'=>$user->user_name));

        	$rule=explode(',',$x->roles);
        	$allow = !is_null($x) && (in_array('SUPER_ADMIN', $rule) || in_array('ADMIN', $rule)) && $x->status==1;

        	return $allow ? FALSE : TRUE;

        }
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('deny',  // deny all users
				'users'=>array('*'),
				'expression'	=>	array($this, 'isAdmin'),
			),
		);
	}

  }
